import { HttpException, HttpStatus } from '@nestjs/common';

/**
 * 自定义400错误异常
 * 用于处理客户端请求错误（除了登录过期外的所有错误）
 */
export class BadRequestException extends HttpException {
  constructor(message: string, code?: string, details?: any) {
    const response = {
      code: code || 'BAD_REQUEST',
      message,
      details,
    };
    super(response, HttpStatus.BAD_REQUEST);
  }
}

/**
 * 业务逻辑异常
 */
export class BusinessException extends HttpException {
  constructor(message: string, code: string = 'BUSINESS_ERROR', details?: any) {
    const response = {
      code,
      message,
      details,
    };
    super(response, HttpStatus.BAD_REQUEST);
  }
}

/**
 * 验证失败异常
 */
export class ValidationException extends HttpException {
  constructor(message: string, details?: any) {
    const response = {
      code: 'VALIDATION_ERROR',
      message,
      details,
    };
    super(response, HttpStatus.BAD_REQUEST);
  }
}

/**
 * 参数错误异常
 */
export class ParameterException extends HttpException {
  constructor(message: string, parameterName?: string) {
    const response = {
      code: 'PARAMETER_ERROR',
      message,
      details: parameterName ? { parameter: parameterName } : null,
    };
    super(response, HttpStatus.BAD_REQUEST);
  }
}
